home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / windows / ocx / midipk.exe / MFEDIT.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-08-30  |  38.3 KB  |  1,167 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Appearance      =   0  'Flat
  4.    AutoRedraw      =   -1  'True
  5.    BorderStyle     =   3  'Fixed Dialog
  6.    Caption         =   "MFEDIT"
  7.    ClientHeight    =   5430
  8.    ClientLeft      =   2100
  9.    ClientTop       =   2190
  10.    ClientWidth     =   9240
  11.    BeginProperty Font 
  12.       name            =   "MS Sans Serif"
  13.       charset         =   1
  14.       weight          =   700
  15.       size            =   8.25
  16.       underline       =   0   'False
  17.       italic          =   0   'False
  18.       strikethrough   =   0   'False
  19.    EndProperty
  20.    ForeColor       =   &H80000008&
  21.    Height          =   6120
  22.    Icon            =   "MFEDIT.frx":0000
  23.    Left            =   2040
  24.    LinkTopic       =   "Form1"
  25.    MaxButton       =   0   'False
  26.    ScaleHeight     =   5430
  27.    ScaleWidth      =   9240
  28.    Top             =   1560
  29.    Width           =   9360
  30.    Begin VB.Frame Frame3 
  31.       Caption         =   "Playback Rate"
  32.       Height          =   855
  33.       Left            =   7080
  34.       TabIndex        =   12
  35.       Top             =   2220
  36.       Width           =   2055
  37.       Begin HslideLib.HSlider PlaybackRateSlider 
  38.          Height          =   375
  39.          Left            =   240
  40.          TabIndex        =   41
  41.          Top             =   360
  42.          Width           =   1575
  43.          _version        =   65537
  44.          _extentx        =   2778
  45.          _extenty        =   661
  46.          _stockprops     =   65
  47.          bevelinner      =   0
  48.          bevelouter      =   0
  49.          bevelwidth      =   1
  50.          borderwidth     =   2
  51.          gap             =   3
  52.          largechange     =   10
  53.          thumbheight     =   360
  54.          thumbstyle      =   2
  55.          thumbwidth      =   120
  56.          tickcolor       =   0
  57.          tickcount       =   11
  58.          ticklength      =   4
  59.          tickmarks       =   3
  60.          tickwidth       =   1
  61.          trackbevel      =   0
  62.          trackwidth      =   0
  63.          value           =   0
  64.          max             =   500
  65.          min             =   -500
  66.       End
  67.    End
  68.    Begin VB.Frame Frame5 
  69.       Caption         =   "Playback Controls"
  70.       Height          =   2115
  71.       Left            =   7080
  72.       TabIndex        =   30
  73.       Top             =   3180
  74.       Width           =   2055
  75.       Begin VB.CommandButton CmdStop 
  76.          Appearance      =   0  'Flat
  77.          BackColor       =   &H80000005&
  78.          Caption         =   "Stop"
  79.          Height          =   435
  80.          Left            =   120
  81.          TabIndex        =   31
  82.          Top             =   1500
  83.          Width           =   1815
  84.       End
  85.       Begin VB.CommandButton CmdRecord 
  86.          Appearance      =   0  'Flat
  87.          BackColor       =   &H80000005&
  88.          Caption         =   "Record"
  89.          Height          =   435
  90.          Left            =   120
  91.          TabIndex        =   32
  92.          Top             =   900
  93.          Width           =   1815
  94.       End
  95.       Begin VB.CommandButton CmdPlay 
  96.          Appearance      =   0  'Flat
  97.          BackColor       =   &H80000005&
  98.          Caption         =   "Play"
  99.          Height          =   435
  100.          Left            =   120
  101.          TabIndex        =   33
  102.          Top             =   300
  103.          Width           =   1815
  104.       End
  105.    End
  106.    Begin VB.Frame Frame4 
  107.       Caption         =   "MIDI File Settings"
  108.       Height          =   2175
  109.       Left            =   7080
  110.       TabIndex        =   36
  111.       Top             =   -30
  112.       Width           =   2055
  113.       Begin VB.Label LabelTicks 
  114.          Alignment       =   2  'Center
  115.          Appearance      =   0  'Flat
  116.          BackColor       =   &H00000000&
  117.          Caption         =   "Tick"
  118.          BeginProperty Font 
  119.             name            =   "MS Sans Serif"
  120.             charset         =   1
  121.             weight          =   400
  122.             size            =   9.75
  123.             underline       =   0   'False
  124.             italic          =   0   'False
  125.             strikethrough   =   0   'False
  126.          EndProperty
  127.          ForeColor       =   &H0000FF00&
  128.          Height          =   255
  129.          Left            =   240
  130.          TabIndex        =   37
  131.          Top             =   1800
  132.          Width           =   1635
  133.       End
  134.       Begin VB.Label LabelTimeSignature 
  135.          Alignment       =   2  'Center
  136.          Appearance      =   0  'Flat
  137.          BackColor       =   &H00000000&
  138.          BorderStyle     =   1  'Fixed Single
  139.          Caption         =   "Time Signature"
  140.          BeginProperty Font 
  141.             name            =   "MS Sans Serif"
  142.             charset         =   1
  143.             weight          =   400
  144.             size            =   9.75
  145.             underline       =   0   'False
  146.             italic          =   0   'False
  147.             strikethrough   =   0   'False
  148.          EndProperty
  149.          ForeColor       =   &H0000FF00&
  150.          Height          =   315
  151.          Left            =   240
  152.          TabIndex        =   34
  153.          Top             =   540
  154.          Width           =   1635
  155.       End
  156.       Begin VB.Label LabelTempo 
  157.          Alignment       =   2  'Center
  158.          Appearance      =   0  'Flat
  159.          BackColor       =   &H00000000&
  160.          BorderStyle     =   1  'Fixed Single
  161.          Caption         =   "Tempo"
  162.          BeginProperty Font 
  163.             name            =   "MS Sans Serif"
  164.             charset         =   1
  165.             weight          =   400
  166.             size            =   9.75
  167.             underline       =   0   'False
  168.             italic          =   0   'False
  169.             strikethrough   =   0   'False
  170.          EndProperty
  171.          ForeColor       =   &H0000FF00&
  172.          Height          =   315
  173.          Left            =   240
  174.          TabIndex        =   35
  175.          Top             =   1140
  176.          Width           =   1635
  177.       End
  178.       Begin VB.Label Label7 
  179.          Alignment       =   2  'Center
  180.          Appearance      =   0  'Flat
  181.          Caption         =   "Time Signature"
  182.          BeginProperty Font 
  183.             name            =   "MS Sans Serif"
  184.             charset         =   1
  185.             weight          =   400
  186.             size            =   9.75
  187.             underline       =   0   'False
  188.             italic          =   0   'False
  189.             strikethrough   =   0   'False
  190.          EndProperty
  191.          ForeColor       =   &H80000008&
  192.          Height          =   255
  193.          Left            =   120
  194.          TabIndex        =   40
  195.          Top             =   300
  196.          Width           =   1815
  197.       End
  198.       Begin VB.Label Label8 
  199.          Alignment       =   2  'Center
  200.          Appearance      =   0  'Flat
  201.          Caption         =   "Tempo"
  202.          BeginProperty Font 
  203.             name            =   "MS Sans Serif"
  204.             charset         =   1
  205.             weight          =   400
  206.             size            =   9.75
  207.             underline       =   0   'False
  208.             italic          =   0   'False
  209.             strikethrough   =   0   'False
  210.          EndProperty
  211.          ForeColor       =   &H80000008&
  212.          Height          =   255
  213.          Left            =   120
  214.          TabIndex        =   39
  215.          Top             =   900
  216.          Width           =   1815
  217.       End
  218.       Begin VB.Label Label9 
  219.          Alignment       =   2  'Center
  220.          Appearance      =   0  'Flat
  221.          Caption         =   "Ticks Per Quarter Note"
  222.          BeginProperty Font 
  223.             name            =   "MS Sans Serif"
  224.             charset         =   1
  225.             weight          =   400
  226.             size            =   8.25
  227.             underline       =   0   'False
  228.             italic          =   0   'False
  229.             strikethrough   =   0   'False
  230.          EndProperty
  231.          ForeColor       =   &H80000008&
  232.          Height          =   255
  233.          Left            =   120
  234.          TabIndex        =   38
  235.          Top             =   1560
  236.          Width           =   1815
  237.       End
  238.    End
  239.    Begin VB.PictureBox Picture1 
  240.       BorderStyle     =   0  'None
  241.       Height          =   435
  242.       Left            =   60
  243.       ScaleHeight     =   435
  244.       ScaleWidth      =   6915
  245.       TabIndex        =   19
  246.       Top             =   60
  247.       Width           =   6915
  248.       Begin VB.CheckBox MidiThruCheck 
  249.          Caption         =   "Midi Thru"
  250.          Height          =   255
  251.          Left            =   2820
  252.          TabIndex        =   22
  253.          Top             =   60
  254.          Value           =   1  'Checked
  255.          Width           =   1155
  256.       End
  257.       Begin VB.ComboBox InputDevCombo 
  258.          Appearance      =   0  'Flat
  259.          Height          =   300
  260.          Left            =   60
  261.          Style           =   2  'Dropdown List
  262.          TabIndex        =   18
  263.          Top             =   60
  264.          Width           =   2535
  265.       End
  266.       Begin VB.ComboBox OutputDevCombo 
  267.          Appearance      =   0  'Flat
  268.          Height          =   300
  269.          Left            =   4140
  270.          Style           =   2  'Dropdown List
  271.          TabIndex        =   20
  272.          Top             =   60
  273.          Width           =   2535
  274.       End
  275.    End
  276.    Begin VB.Frame Frame2 
  277.       Caption         =   "Tracks"
  278.       Height          =   4755
  279.       Left            =   60
  280.       TabIndex        =   13
  281.       Top             =   540
  282.       Width           =   3195
  283.       Begin VB.ListBox TrackList 
  284.          Appearance      =   0  'Flat
  285.          Height          =   2955
  286.          Left            =   120
  287.          TabIndex        =   17
  288.          Top             =   300
  289.          Width           =   2955
  290.       End
  291.       Begin VB.CommandButton CmdInsertTrack 
  292.          Appearance      =   0  'Flat
  293.          BackColor       =   &H80000005&
  294.          Caption         =   "Insert New Track"
  295.          Height          =   435
  296.          Left            =   120
  297.          TabIndex        =   16
  298.          Top             =   4260
  299.          Width           =   2955
  300.       End
  301.       Begin VB.CommandButton CmdDeleteTrack 
  302.          Appearance      =   0  'Flat
  303.          BackColor       =   &H80000005&
  304.          Caption         =   "Delete Current Track"
  305.          Height          =   435
  306.          Left            =   120
  307.          TabIndex        =   15
  308.          Top             =   3780
  309.          Width           =   2955
  310.       End
  311.       Begin VB.CommandButton CmdQueueTrack 
  312.          Appearance      =   0  'Flat
  313.          BackColor       =   &H80000005&
  314.          Caption         =   "Queue Current Track"
  315.          Height          =   435
  316.          Left            =   120
  317.          TabIndex        =   14
  318.          Top             =   3300
  319.          Width           =   2955
  320.       End
  321.    End
  322.    Begin VB.Frame Frame1 
  323.       Caption         =   "Messages"
  324.       Height          =   4755
  325.       Left            =   3330
  326.       TabIndex        =   4
  327.       Top             =   540
  328.       Width           =   3675
  329.       Begin VB.PictureBox Picture2 
  330.          BorderStyle     =   0  'None
  331.          Height          =   1875
  332.          Left            =   120
  333.          ScaleHeight     =   1875
  334.          ScaleWidth      =   3495
  335.          TabIndex        =   23
  336.          Top             =   2820
  337.          Width           =   3495
  338.          Begin VB.TextBox MessageEdit 
  339.             Appearance      =   0  'Flat
  340.             Height          =   285
  341.             Left            =   1020
  342.             TabIndex        =   29
  343.             Top             =   60
  344.             Width           =   555
  345.          End
  346.          Begin VB.TextBox Data1Edit 
  347.             Appearance      =   0  'Flat
  348.             Height          =   285
  349.             Left            =   1020
  350.             TabIndex        =   28
  351.             Top             =   420
  352.             Width           =   555
  353.          End
  354.          Begin VB.TextBox Data2Edit 
  355.             Appearance      =   0  'Flat
  356.             Height          =   285
  357.             Left            =   2700
  358.             TabIndex        =   27
  359.             Top             =   420
  360.             Width           =   555
  361.          End
  362.          Begin VB.TextBox TimeEdit 
  363.             Appearance      =   0  'Flat
  364.             Height          =   285
  365.             Left            =   1020
  366.             TabIndex        =   26
  367.             Top             =   780
  368.             Width           =   1035
  369.          End
  370.          Begin VB.TextBox BufferEdit 
  371.             Appearance      =   0  'Flat
  372.             Height          =   285
  373.             Left            =   1020
  374.             TabIndex        =   25
  375.             Top             =   1140
  376.             Width           =   2415
  377.          End
  378.          Begin VB.TextBox MsgTextEdit 
  379.             Appearance      =   0  'Flat
  380.             Height          =   285
  381.             Left            =   1020
  382.             TabIndex        =   24
  383.             Top             =   1500
  384.             Width           =   2415
  385.          End
  386.          Begin VB.Label Label1 
  387.             Alignment       =   1  'Right Justify
  388.             Caption         =   "Message:"
  389.             Height          =   255
  390.             Left            =   60
  391.             TabIndex        =   6
  392.             Top             =   60
  393.             Width           =   855
  394.          End
  395.          Begin VB.Label Label2 
  396.             Alignment       =   1  'Right Justify
  397.             Caption         =   "Data1:"
  398.             Height          =   255
  399.             Left            =   60
  400.             TabIndex        =   7
  401.             Top             =   420
  402.             Width           =   855
  403.          End
  404.          Begin VB.Label Label3 
  405.             Alignment       =   1  'Right Justify
  406.             Caption         =   "Data2:"
  407.             Height          =   255
  408.             Left            =   1740
  409.             TabIndex        =   8
  410.             Top             =   420
  411.             Width           =   855
  412.          End
  413.          Begin VB.Label Label4 
  414.             Alignment       =   1  'Right Justify
  415.             Caption         =   "Buffer:"
  416.             Height          =   255
  417.             Left            =   60
  418.             TabIndex        =   9
  419.             Top             =   1140
  420.             Width           =   855
  421.          End
  422.          Begin VB.Label Label5 
  423.             Alignment       =   1  'Right Justify
  424.             Caption         =   "Time:"
  425.             Height          =   255
  426.             Left            =   60
  427.             TabIndex        =   10
  428.             Top             =   780
  429.             Width           =   855
  430.          End
  431.          Begin VB.Label Label6 
  432.             Caption         =   "MsgText:"
  433.             Height          =   255
  434.             Left            =   120
  435.             TabIndex        =   11
  436.             Top             =   1500
  437.             Width           =   795
  438.          End
  439.       End
  440.       Begin VB.CheckBox InsertRecordingCheck 
  441.          Caption         =   "Insert Recording"
  442.          Height          =   255
  443.          Left            =   1620
  444.          TabIndex        =   21
  445.          Top             =   2520
  446.          Width           =   1755
  447.       End
  448.       Begin VB.CommandButton CmdDeleteMessage 
  449.          Appearance      =   0  'Flat
  450.          BackColor       =   &H80000005&
  451.          Caption         =   "Delete"
  452.          Height          =   315
  453.          Left            =   2700
  454.          TabIndex        =   0
  455.          Top             =   2160
  456.          Width           =   855
  457.       End
  458.       Begin VB.CommandButton CmdInsertMessage 
  459.          Appearance      =   0  'Flat
  460.          BackColor       =   &H80000005&
  461.          Caption         =   "Insert"
  462.          Height          =   315
  463.          Left            =   1440
  464.          TabIndex        =   1
  465.          Top             =   2160
  466.          Width           =   855
  467.       End
  468.       Begin VB.CommandButton CmdModifyMessage 
  469.          Appearance      =   0  'Flat
  470.          BackColor       =   &H80000005&
  471.          Caption         =   "Modify"
  472.          Height          =   315
  473.          Left            =   120
  474.          TabIndex        =   2
  475.          Top             =   2160
  476.          Width           =   855
  477.       End
  478.       Begin VB.CheckBox HexCheck 
  479.          Caption         =   "Hexadecimal"
  480.          Height          =   255
  481.          Left            =   180
  482.          TabIndex        =   3
  483.          Top             =   2520
  484.          Value           =   1  'Checked
  485.          Width           =   1455
  486.       End
  487.       Begin VB.ListBox MessageList 
  488.          Appearance      =   0  'Flat
  489.          Height          =   1785
  490.          Left            =   120
  491.          TabIndex        =   5
  492.          Top             =   300
  493.          Width           =   3435
  494.       End
  495.    End
  496.    Begin MidifileLib.Midifile Midifile1 
  497.       Left            =   4440
  498.       Top             =   5400
  499.       _version        =   65537
  500.       _extentx        =   847
  501.       _extenty        =   847
  502.       _stockprops     =   0
  503.       filename        =   ""
  504.    End
  505.    Begin MidiioLib.MIDIOutput MIDIOutput1 
  506.       Left            =   3840
  507.       Top             =   5400
  508.       _version        =   65537
  509.       _extentx        =   847
  510.       _extenty        =   847
  511.       _stockprops     =   0
  512.       deviceid        =   0
  513.       volumeleft      =   -1
  514.       volumeright     =   -1
  515.    End
  516.    Begin MidiioLib.MIDIInput MIDIInput1 
  517.       Left            =   3240
  518.       Top             =   5400
  519.       _version        =   65537
  520.       _extentx        =   847
  521.       _extenty        =   847
  522.       _stockprops     =   0
  523.    End
  524.    Begin MSComDlg.CommonDialog CMDialog1 
  525.       Left            =   2700
  526.       Top             =   5340
  527.       _version        =   65536
  528.       _extentx        =   847
  529.       _extenty        =   847
  530.       _stockprops     =   0
  531.       cancelerror     =   -1  'True
  532.       defaultext      =   "mid"
  533.       filter          =   "Open MIDI File"
  534.       filterindex     =   290
  535.       fontsize        =   2.98738e-38
  536.    End
  537.    Begin VB.Menu FileMenu 
  538.       Caption         =   "&File"
  539.       Begin VB.Menu FileNew 
  540.          Caption         =   "&New"
  541.       End
  542.       Begin VB.Menu FileOpen 
  543.          Caption         =   "&Open..."
  544.       End
  545.       Begin VB.Menu FileSave 
  546.          Caption         =   "&Save"
  547.       End
  548.       Begin VB.Menu FileSaveAs 
  549.          Caption         =   "Save &As..."
  550.       End
  551.       Begin VB.Menu FileSep1 
  552.          Caption         =   "-"
  553.       End
  554.       Begin VB.Menu FileExit 
  555.          Caption         =   "E&xit"
  556.       End
  557.    End
  558. Attribute VB_Name = "Form1"
  559. Attribute VB_Creatable = False
  560. Attribute VB_Exposed = False
  561. Option Explicit
  562. Dim msPerTick(50) As Long
  563. Dim ticksPerMs(50) As Long
  564. Dim fModified As Integer
  565. Dim fGotFirst As Integer
  566. Dim fRecording As Integer
  567. Dim CurrentTime As Double
  568. Dim PreviousTime As Double
  569. Dim InCurrentTime As Double
  570. Dim InPreviousTime As Double
  571. Dim TempoTime(50) As Long
  572. Dim TempoSetting(50) As Long
  573. Dim TotalTempoChanges As Integer
  574. Dim Lyric(1000) As String
  575. Private Sub CloseInputDevice()
  576.     '
  577.     ' Close if open
  578.     '
  579.     If MIDIInput1.State >= MIDISTATE_OPEN Then
  580.         MIDIInput1.Action = MIDIIN_CLOSE
  581.     End If
  582. End Sub
  583. Private Sub CloseOutputDevice()
  584.     If MIDIOutput1.State >= MIDISTATE_OPEN Then
  585.         MIDIOutput1.Action = MIDIOUT_CLOSE
  586.     End If
  587. End Sub
  588. Private Sub CmdDeleteMessage_Click()
  589.     MIDIFile1.Action = MIDIFILE_DELETE_MESSAGE
  590.     fModified = True
  591.     DisplayTrack (TrackList.ListIndex + 1)
  592. End Sub
  593. Private Sub CmdDeleteTrack_Click()
  594.     Dim t As Integer
  595.     If TrackList.ListIndex = -1 Then
  596.       MsgBox "No track slected."
  597.       Exit Sub
  598.       End If
  599.     MIDIFile1.TrackNumber = TrackList.ListIndex + 1
  600.     MIDIFile1.Action = MIDIFILE_DELETE_TRACK
  601.     fModified = True
  602.     t = TrackList.ListIndex
  603.     DisplayTrackList
  604.     If (t > TrackList.ListCount - 1) Then
  605.         t = t - 1
  606.     End If
  607.     TrackList.ListIndex = t
  608. End Sub
  609. Private Sub CmdInsertMessage_Click()
  610.     MIDIFile1.Message = FetchNumber(CStr(MessageEdit.Text))
  611.     MIDIFile1.Data1 = FetchNumber(CStr(Data1Edit.Text))
  612.     MIDIFile1.Data2 = FetchNumber(CStr(Data2Edit.Text))
  613.     MIDIFile1.Time = FetchNumber(CStr(TimeEdit.Text))
  614.     MIDIFile1.Action = MIDIFILE_INSERT_MESSAGE
  615.     fModified = True
  616.     DisplayTrack (TrackList.ListIndex + 1)
  617. End Sub
  618. Private Sub CmdInsertTrack_Click()
  619.     Dim t As Integer
  620.     If TrackList.ListIndex = -1 Then
  621.         MIDIFile1.TrackNumber = 1
  622.         MIDIFile1.Action = MIDIFILE_INSERT_TRACK
  623.         fModified = True
  624.         t = TrackList.ListIndex
  625.         DisplayTrackList
  626.         TrackList.ListIndex = t + 1
  627.     Else
  628.         MIDIFile1.TrackNumber = TrackList.ListIndex + 1
  629.         MIDIFile1.Action = MIDIFILE_INSERT_TRACK
  630.         fModified = True
  631.         t = TrackList.ListIndex
  632.         DisplayTrackList
  633.         TrackList.ListIndex = t + 1
  634.         End If
  635. End Sub
  636. Private Sub CmdModifyMessage_Click()
  637.     Dim m As Integer
  638.     MIDIFile1.Message = FetchNumber(CStr(MessageEdit.Text))
  639.     MIDIFile1.Data1 = FetchNumber(CStr(Data1Edit.Text))
  640.     MIDIFile1.Data2 = FetchNumber(CStr(Data2Edit.Text))
  641.     MIDIFile1.Time = FetchNumber(CStr(TimeEdit.Text))
  642.     MIDIFile1.Buffer = BufferEdit.Text
  643.     MIDIFile1.MsgText = MsgTextEdit.Text
  644.     MIDIFile1.Action = MIDIFILE_MODIFY_MESSAGE
  645.     m = MIDIFile1.MessageNumber
  646.     fModified = True
  647.     DisplayTrack (TrackList.ListIndex + 1)
  648.     If (m > MIDIFile1.MessageCount) Then
  649.         m = m - 1
  650.     End If
  651.     MessageList.ListIndex = m
  652. End Sub
  653. Private Sub CmdPlay_Click()
  654.     StartPlay
  655. End Sub
  656. Private Sub CmdQueueTrack_Click()
  657.     If TrackList.ListIndex = -1 Then
  658.       MsgBox "No track selected."
  659.       Exit Sub
  660.       End If
  661.       
  662.     CmdQueueTrack.Enabled = False
  663.     CmdDeleteTrack.Enabled = False
  664.     CmdInsertTrack.Enabled = False
  665.     Screen.MousePointer = 11
  666.     QueueTrack (TrackList.ListIndex + 1)
  667.     On Error Resume Next
  668.     TrackList.ListIndex = TrackList.ListIndex + 1
  669.     On Error GoTo 0
  670.     Screen.MousePointer = 0
  671.     CmdQueueTrack.Enabled = True
  672.     CmdDeleteTrack.Enabled = True
  673.     CmdInsertTrack.Enabled = True
  674. End Sub
  675. Private Sub CmdRecord_Click()
  676.     InsertRecordingCheck.Value = 1
  677.     StartPlay
  678.     StartRecording
  679. End Sub
  680. Private Sub CmdStop_Click()
  681.     StopPlay
  682.     StopRecording
  683. End Sub
  684. Private Sub DisplayTrack(t As Integer)
  685.     Dim i As Integer
  686.     Screen.MousePointer = 11
  687.     MessageList.Clear
  688.     MIDIFile1.TrackNumber = t
  689.     For i = 1 To MIDIFile1.MessageCount
  690.         If (i > 500) Then
  691.             Exit For
  692.             End If
  693.         MIDIFile1.MessageNumber = i
  694.         '
  695.         'Meta Event
  696.         '
  697.         If (MIDIFile1.Message = META) Then
  698.             Select Case MIDIFile1.Data1
  699.                 Case META_SEQUENCE_NUMBER
  700.                     MessageList.AddItem "Sequence number " & Hex$(MIDIFile1.Data2) & " : " & MIDIFile1.MsgText
  701.                 Case META_TEXT
  702.                     MessageList.AddItem "Text " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  703.                 Case META_COPYRIGHT
  704.                     MessageList.AddItem "Copyright " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  705.                 Case META_NAME
  706.                     MessageList.AddItem "Track Name " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  707.                 Case META_INST_NAME
  708.                     MessageList.AddItem "Instrument Name " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  709.                 Case META_LYRIC
  710.                     MessageList.AddItem "Lyric " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  711.                 Case META_MARKER
  712.                     MessageList.AddItem "Marker " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  713.                 Case META_CUE_POINT
  714.                     MessageList.AddItem "Cue point " & Hex$(MIDIFile1.Data1) & " : " & MIDIFile1.MsgText
  715.                 Case META_TEMPO
  716.                     MessageList.AddItem Str(MIDIFile1.Time) & " Tempo " & Int(60000000 / MIDIFile1.Tempo)
  717.                 Case META_TIME_SIG
  718.                     MessageList.AddItem Str(MIDIFile1.Time) & " Time Signature " & MIDIFile1.Numerator & "/" & (2 ^ MIDIFile1.Denominator)
  719.                 Case Else
  720.                     MessageList.AddItem "Sysex " & Hex$(MIDIFile1.Data1)
  721.                 End Select
  722.         Else
  723.             Select Case (MIDIFile1.Message And &HF0)
  724.                 Case NOTE_OFF
  725.                     MessageList.AddItem "Note Off " & Hex$(MIDIFile1.Message)
  726.                 Case NOTE_ON
  727.                     MessageList.AddItem "Note On " & Hex$(MIDIFile1.Message)
  728.                 Case POLY_KEY_PRESS
  729.                     MessageList.AddItem "Poly Key Press " & Hex$(MIDIFile1.Message)
  730.                 Case CONTROLLER_CHANGE
  731.                     MessageList.AddItem "Controller Change " & Hex$(MIDIFile1.Message)
  732.                 Case PROGRAM_CHANGE
  733.                     MessageList.AddItem "Program Change " & Hex$(MIDIFile1.Message)
  734.                 Case CHANNEL_PRESSURE
  735.                     MessageList.AddItem "Channel Pressure " & Hex$(MIDIFile1.Message)
  736.                 Case PITCH_BEND
  737.                     MessageList.AddItem "Pitch Bend " & Hex$(MIDIFile1.Message)
  738.                 Case Else
  739.                     MessageList.AddItem Hex$(MIDIFile1.Message)
  740.                 End Select
  741.             End If
  742.         Next i
  743.     Screen.MousePointer = 0
  744.     End Sub
  745. Private Sub DisplayTrackList()
  746.     Dim m As Integer
  747.     Dim t As Integer
  748.     TrackList.Clear
  749.     For t = 1 To MIDIFile1.NumberOfTracks
  750.         TrackList.AddItem GetTrackName(t)
  751.     Next
  752.     GetTempoChanges
  753.     GetTimeSignature
  754. End Sub
  755. Private Function FetchNumber(s As String) As Integer
  756.     If (HexCheck.Value) Then
  757.         FetchNumber = Val("&H" & s)
  758.     Else
  759.         FetchNumber = Val(s)
  760.     End If
  761. End Function
  762. Private Sub FileExit_Click()
  763.     If (OkToExit()) Then
  764.         End
  765.     End If
  766. End Sub
  767. Private Sub FileNew_Click()
  768.     Dim wRtn As Integer
  769.     Dim ts As Variant
  770.     If (fModified) Then
  771.         wRtn = MsgBox("Discard changes to current file?", 36)
  772.         If (wRtn <> 6) Then
  773.             Exit Sub
  774.         End If
  775.     End If
  776.     MIDIFile1.filename = "Untitled.mid"
  777.     Form1.Caption = "Untitled.mid"
  778.     On Error Resume Next
  779.     ts = FileDateTime("Untitled.mid")
  780.     wRtn = Err
  781.     On Error GoTo 0
  782.     If (wRtn = 0) Then
  783.         wRtn = MsgBox("Untitled.mid already exists, do you want to recreate it?", 36)
  784.         If (wRtn = 6) Then
  785.             Kill "Untitled.mid"
  786.             wRtn = 1
  787.         Else
  788.             wRtn = 0
  789.         End If
  790.     Else
  791.         wRtn = 1
  792.     End If
  793.     If (wRtn) Then
  794.         MIDIFile1.Action = MIDIFILE_CREATE
  795.         MIDIFile1.Action = MIDIFILE_SAVE
  796.     Else
  797.         MIDIFile1.Action = MIDIFILE_OPEN
  798.     End If
  799.     DisplayTrackList
  800.     TrackList.ListIndex = 0
  801.     fModified = 0
  802. End Sub
  803. Private Sub FileOpen_Click()
  804.     On Error Resume Next
  805.     CMDialog1.DialogTitle = "Open MIDI File"
  806.     CMDialog1.Filter = "(*.mid) MIDI files|*.mid|"
  807.     CMDialog1.DefaultExt = "mid"
  808.     CMDialog1.FilterIndex = 0
  809.     CMDialog1.Flags = &H1000&
  810.     CMDialog1.Action = 1
  811.     If (Err) Then
  812.         Exit Sub
  813.     End If
  814.     DoEvents
  815.     Screen.MousePointer = 11
  816.     MIDIFile1.filename = CMDialog1.filename
  817.     MIDIFile1.Action = MIDIFILE_OPEN
  818.     DisplayTrackList
  819.     TrackList.ListIndex = 1
  820.     fModified = 0
  821.     Screen.MousePointer = 0
  822.     End Sub
  823. Private Sub FileSave_Click()
  824.     MIDIFile1.Action = MIDIFILE_SAVE
  825. End Sub
  826. Private Sub FileSaveAs_Click()
  827.     If (SaveAs()) Then
  828.         Form1.Caption = CMDialog1.filename
  829.     End If
  830. End Sub
  831. Private Sub Form_Load()
  832.     Dim i As Integer
  833.     '
  834.     ' Fill output device combo box
  835.     '
  836.     For i = -1 To MIDIOutput1.DeviceCount - 1
  837.         MIDIOutput1.DeviceID = i
  838.         OutputDevCombo.AddItem MIDIOutput1.ProductName
  839.     Next
  840.     '
  841.     ' Select first in list
  842.     '
  843.     MIDIOutput1.DeviceID = -1
  844.     OutputDevCombo.ListIndex = 0
  845.     '
  846.     ' Fill input device combo box
  847.     '
  848.     For i = 0 To MIDIInput1.DeviceCount - 1
  849.         MIDIInput1.DeviceID = i
  850.         InputDevCombo.AddItem MIDIInput1.ProductName
  851.     Next
  852.     '
  853.     ' Select first in list
  854.     '
  855.     MIDIInput1.DeviceID = 0
  856.     InputDevCombo.ListIndex = 0
  857.     fModified = 0
  858.     Form1.Show
  859. End Sub
  860. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  861.     If (OkToExit() <> True) Then
  862.         Cancel = True
  863.     End If
  864. End Sub
  865. Private Sub Form_Unload(Cancel As Integer)
  866.     CloseOutputDevice
  867.     CloseInputDevice
  868. End Sub
  869. Private Function FormatNumber(n As Long) As String
  870.     If (HexCheck.Value) Then
  871.         If n > 256 Then
  872.             Beep
  873.             End If
  874.         FormatNumber = Hex$(n)
  875.     Else
  876.         FormatNumber = Format(n)
  877.         End If
  878.     End Function
  879. Private Sub GetTempoChanges()
  880.     Dim m As Integer
  881.     Dim TempoChangeCount As Integer
  882.     Dim CurrentTime As Long
  883.     Screen.MousePointer = 11
  884.     TotalTempoChanges = 0
  885.     MIDIFile1.TrackNumber = 1
  886.     For m = 1 To MIDIFile1.MessageCount
  887.         MIDIFile1.MessageNumber = m
  888.         
  889.         'Meta Tempo Event
  890.         If (MIDIFile1.Message = 255) And MIDIFile1.Data1 = &H51 Then
  891.             'Keep track of the total number of tempo changes in this MIDI file
  892.             TotalTempoChanges = TotalTempoChanges + 1
  893.             'This is the tempo
  894.             TempoSetting(TotalTempoChanges) = MIDIFile1.Tempo
  895.             'Calculate msPerTick at this tempo -- this is used when playing back MIDI input
  896.             msPerTick(TotalTempoChanges) = TempoSetting(TotalTempoChanges) / 1000 / MIDIFile1.TicksPerQuarterNote
  897.             'Calculate ticksPerMs at this tempo -- this is used when recoding MIDI input
  898.             ticksPerMs(TotalTempoChanges) = MIDIFile1.TicksPerQuarterNote / TempoSetting(TotalTempoChanges) * 1000
  899.                     
  900.             TempoTime(TotalTempoChanges) = TempoTime(TotalTempoChanges - 1) + MIDIFile1.Time * msPerTick(TotalTempoChanges)
  901.             'Display the first tempo
  902.             LabelTempo.Caption = Int(60000000 / TempoSetting(1))
  903.             'Display TickperQuarterNote
  904.             LabelTicks.Caption = MIDIFile1.TicksPerQuarterNote
  905.         End If
  906.     Next
  907.     Screen.MousePointer = 0
  908. End Sub
  909. Private Sub GetTimeSignature()
  910.     Dim m As Integer
  911.     MIDIFile1.TrackNumber = 1
  912.     For m = 1 To MIDIFile1.MessageCount
  913.         MIDIFile1.MessageNumber = m
  914.         
  915.         'Meta Event Key Signature
  916.         If (MIDIFile1.Message = 255) And MIDIFile1.Data1 = &H58 Then
  917.             LabelTimeSignature.Caption = MIDIFile1.Numerator & "/" & MIDIFile1.Denominator ^ 2
  918.         End If
  919.     Next
  920. End Sub
  921. Private Function GetTrackName(Track As Integer) As String
  922.     Dim i As Integer
  923.     MIDIFile1.TrackNumber = Track
  924.     For i = 1 To MIDIFile1.MessageCount
  925.         MIDIFile1.MessageNumber = i
  926.         '
  927.         'Meta Event
  928.         '
  929.         If (MIDIFile1.Message = 255) And MIDIFile1.Data1 = 3 Then
  930.             If (MIDIFile1.MsgText = "") Then
  931.                 GetTrackName = "Track" & Str(Track) & " (null)"
  932.             Else
  933.                 GetTrackName = MIDIFile1.MsgText
  934.             End If
  935.             Exit Function
  936.         End If
  937.     Next
  938.     GetTrackName = "Track" & Str(Track)
  939. End Function
  940. Private Sub InputDevCombo_Click()
  941.     '
  942.     ' Stop and Close currently opened device (if any)
  943.     '
  944.     StopRecording
  945. End Sub
  946. Private Sub MessageList_Click()
  947.     MIDIFile1.MessageNumber = MessageList.ListIndex + 1
  948.     TimeEdit.Text = FormatNumber(CLng(MIDIFile1.Time))
  949.     MessageEdit.Text = FormatNumber(CLng(MIDIFile1.Message))
  950.     Data1Edit.Text = FormatNumber(CLng(MIDIFile1.Data1))
  951.     Data2Edit.Text = FormatNumber(CLng(MIDIFile1.Data2))
  952.     BufferEdit.Text = MIDIFile1.Buffer
  953.     MsgTextEdit.Text = MIDIFile1.MsgText
  954. End Sub
  955. Private Sub MIDIInput1_Message()
  956.     Dim InMessage As Integer
  957.     Dim InData1 As Integer
  958.     Dim InData2 As Integer
  959.     Dim Y As Integer
  960.     If (fGotFirst = False) Then
  961.         InPreviousTime = MIDIInput1.Time
  962.         fGotFirst = True
  963.         fRecording = True
  964.     End If
  965.     '
  966.     'This do while loop allows you to take all the messages that are
  967.     'waiting in the message queue.
  968.     '
  969.     Do While MIDIInput1.MessageCount > 0
  970.         '
  971.         'This is the incoming MIDI data
  972.         '
  973.         InMessage = MIDIInput1.Message
  974.         InData1 = MIDIInput1.Data1
  975.         InData2 = MIDIInput1.Data2
  976.         '
  977.         ' Copy input to output?
  978.         '
  979.         If (MidiThruCheck.Value) Then
  980.             '
  981.             'Tell MIDIOutput1 to send the MIDI data
  982.             '
  983.             MIDIOutput1.Message = InMessage
  984.             MIDIOutput1.Data1 = InData1
  985.             MIDIOutput1.Data2 = InData2
  986.             MIDIOutput1.Action = MIDIOUT_SEND
  987.         End If
  988.         If (InsertRecordingCheck.Value) And InMessage < 254 Then
  989.             
  990.             ' Copy message parameters
  991.             MIDIFile1.Message = InMessage
  992.             MIDIFile1.Data1 = InData1
  993.             MIDIFile1.Data2 = InData2
  994.             
  995.             ' Calculate time in ticks
  996.             InCurrentTime = MIDIInput1.Time
  997.             MIDIFile1.Time = (InCurrentTime - InPreviousTime) * msPerTick(1)
  998.             InPreviousTime = InCurrentTime
  999.             ' insert message into MIDI file
  1000.             MIDIFile1.Action = MIDIFILE_INSERT_MESSAGE
  1001.         End If
  1002.         '
  1003.         'Remove the MIDI data from the MIDI IN queue
  1004.         '
  1005.         MIDIInput1.Action = MIDIIN_REMOVE
  1006.     Loop
  1007. End Sub
  1008. Private Sub MIDIOutput1_Error(ErrorCode As Integer, ErrorMessage As String)
  1009.    If (ErrorCode <> 0) And (ErrorCode <> 8) Then
  1010.       MsgBox ErrorMessage
  1011.       End If
  1012. End Sub
  1013. Private Sub MIDIOutput1_MessageSent(MessageTag As Long)
  1014.     LabelTempo.Caption = Str$(Int(60000000 / TempoSetting(MessageTag)))
  1015. End Sub
  1016. Private Sub MIDIOutput1_QueueEmpty()
  1017.     StopPlay
  1018. End Sub
  1019. Private Function OkToExit() As Integer
  1020.     Dim wRtn As Integer
  1021.     If (fModified) Then
  1022.         wRtn = MsgBox("Save file before exiting?", 36)
  1023.         If (wRtn = 6) Then
  1024.             If (MIDIFile1.filename = "Untitled.mid") Then
  1025.                 If (SaveAs() = False) Then
  1026.                    OkToExit = False
  1027.                    Exit Function
  1028.                 End If
  1029.             Else
  1030.                 MIDIFile1.Action = MIDIFILE_SAVE
  1031.             End If
  1032.         End If
  1033.     End If
  1034.     OkToExit = True
  1035. End Function
  1036. Private Sub OpenInputDevice()
  1037.     MIDIInput1.DeviceID = InputDevCombo.ListIndex
  1038.     MIDIInput1.Action = MIDIIN_OPEN
  1039. End Sub
  1040. Private Sub OpenOutputDevice()
  1041.     '
  1042.     ' Restore defaults
  1043.     '
  1044.     PlaybackRateSlider = 0
  1045.     '
  1046.     ' Open selected device
  1047.     '
  1048.     MIDIOutput1.DeviceID = OutputDevCombo.ListIndex - 1
  1049.     MIDIOutput1.Action = MIDIOUT_OPEN
  1050. End Sub
  1051. Private Sub OutputDevCombo_Click()
  1052.     '
  1053.     ' Stop and Close currently opened device (if any)
  1054.     '
  1055.     StopPlay
  1056. End Sub
  1057. Private Sub QueueTrack(Track As Integer)
  1058.     Dim m As Integer
  1059.     Dim n As Integer
  1060.     Dim i As Double
  1061.     Dim TempoChangeCount As Integer
  1062.     Dim msTickTime As Integer
  1063.     Dim TimerTagCount As Integer
  1064.     PreviousTime = 0
  1065.     CurrentTime = 0
  1066.     TimerTagCount = 0
  1067.     TempoChangeCount = 1
  1068.     MIDIFile1.TrackNumber = Track
  1069.     For m = 1 To MIDIFile1.MessageCount
  1070.         MIDIFile1.MessageNumber = m
  1071.         
  1072.         'Meta Event
  1073.         If (MIDIFile1.Message <> 255) Then
  1074.             'PreviousTime is = to the total ms into the song for this track
  1075.             '
  1076.             'Int(MIDIFile1.Time * msPerTick(TempoChangeCount)) is = to the total ms
  1077.             'that need to pass before playing the next event
  1078.             '
  1079.             CurrentTime = PreviousTime + MIDIFile1.Time * msPerTick(TempoChangeCount)
  1080.             'if the time value of TempoTime(TempoChangeCount) is less than or equal
  1081.             'to the current time, a tempo change is needed.
  1082.             '
  1083.             'Note that msPerTick() is set in Sub GetTempoChanges () at the time a new MIDI
  1084.             'file is loaded.
  1085.             If TotalTempoChanges > TempoChangeCount And TempoTime(TempoChangeCount) <= CurrentTime Then
  1086.                 'Use MessageTag property in MIDIOutput1 fire an event at the time the
  1087.                 'tempo changes so that we can change the LabelTempo.Caption.
  1088.                 '
  1089.                 'See: Sub MIDIOutput1_MessageSent for actual updating of LabelTempo.Caption
  1090.                 MIDIOutput1.MessageTag = TempoChangeCount
  1091.                 TempoChangeCount = TempoChangeCount + 1
  1092.             End If
  1093.             
  1094.             'Time in ms to send this event
  1095.             MIDIOutput1.Time = CurrentTime
  1096.             'Keep track of the CurrentTime for the next event we queue
  1097.             PreviousTime = CurrentTime
  1098.             
  1099.             ' Put message data in control
  1100.             MIDIOutput1.Message = MIDIFile1.Message
  1101.             MIDIOutput1.Data1 = MIDIFile1.Data1
  1102.             MIDIOutput1.Data2 = MIDIFile1.Data2
  1103.             
  1104.             ' Add to output queue
  1105.             MIDIOutput1.Action = MIDIOUT_QUEUE
  1106.         End If
  1107.     DoEvents
  1108.     Next
  1109. End Sub
  1110. Private Function SaveAs() As Integer
  1111.     CMDialog1.DialogTitle = "Save MIDI File As"
  1112.     On Error Resume Next
  1113.     CMDialog1.Flags = &H2&
  1114.     CMDialog1.Action = 2
  1115.     If (Err) Then
  1116.         SaveAs = False
  1117.         Exit Function
  1118.     End If
  1119.     On Error GoTo 0
  1120.     MIDIFile1.filename = CMDialog1.filename
  1121.     MIDIFile1.Action = MIDIFILE_SAVE_AS
  1122.     SaveAs = True
  1123. End Function
  1124. Private Sub StartPlay()
  1125.     OpenOutputDevice
  1126.     MIDIOutput1.Action = MIDIOUT_START
  1127.     CmdPlay.Enabled = False
  1128.     CmdRecord.Enabled = False
  1129.     CmdStop.Enabled = True
  1130. End Sub
  1131. Private Sub StartRecording()
  1132.     OpenInputDevice
  1133.     MIDIInput1.Action = MIDIIN_START
  1134.     'InPreviousTime = MIDIInput1.Time
  1135.     CmdPlay.Enabled = False
  1136.     CmdRecord.Enabled = False
  1137.     CmdStop.Enabled = True
  1138.     fGotFirst = False
  1139. End Sub
  1140. Private Sub StopPlay()
  1141.     MIDIOutput1.Action = MIDIOUT_STOP
  1142.     CloseOutputDevice
  1143.     CmdPlay.Enabled = True
  1144.     CmdRecord.Enabled = True
  1145.     CmdStop.Enabled = False
  1146. End Sub
  1147. Private Sub StopRecording()
  1148.     MIDIInput1.Action = MIDIIN_STOP
  1149.     CloseInputDevice
  1150.     If (MidiThruCheck) Then
  1151.         CloseOutputDevice
  1152.     End If
  1153.     CmdPlay.Enabled = True
  1154.     CmdRecord.Enabled = True
  1155.     CmdStop.Enabled = False
  1156.     fRecording = False
  1157.     If (InsertRecordingCheck) Then
  1158.         DisplayTrack (TrackList.ListIndex + 1)
  1159.     End If
  1160. End Sub
  1161. Private Sub PlaybackRateSlider_Change()
  1162.     MIDIOutput1.PlaybackRate = PlaybackRateSlider.Value
  1163. End Sub
  1164. Private Sub TrackList_Click()
  1165.     DisplayTrack (TrackList.ListIndex + 1)
  1166. End Sub
  1167.